{# SPDX-FileCopyrightText: © 2014-2017 Siemens AG

   SPDX-License-Identifier: FSFAP
#}
{% macro radioGroup(id,options,select,action,separator) %}
  {% for key,disp in options %}
    {% if not loop.first %}{{ separator }}{% endif %}
    <input type="radio" name="{{ id }}" value="{{ key }}"
           {% if key == select %}selected="selected" {% endif %}{{ action }}>{{ disp }}
  {% endfor %}
{% endmacro %}

{% macro table(id, headers) %}
  <table border="1" id="{{ id }}">
    <thead>
      <tr>
        {% for header in headers %}
          <th>
            {{ '{{ header }}'| trans }}
          </th>
        {% endfor %}
      </tr>
    </thead>
  </table>
{% endmacro %}

{% macro select(name, options, id, selected, action, size) %}
  {% if selected is not defined %}
    {% set selected = -1 %}
  {% endif %}
  {% if size is not defined %}
    {% set size = 0 %}
  {% endif %}
  <select name="{{ name }}"{% if id is defined %} id="{{ id }}"{% endif %}{% if size > 0  %} multiple="multiple" size="{{ size }}"{% endif %}{% if action is defined %}
    {{ action}}{% endif %}>
    {% for key, value in options %}
      <option value="{{ key }}"{% if selected == key %} selected="selected"{% endif %}>
        {{ value|e }}
      </option>
    {% endfor %}
  </select>
{% endmacro %}

{% macro selectsingle(name, options, id, selected, action, size) %}
  {% if selected is not defined %}
    {% set selected = -1 %}
  {% endif %}
  {% if size is not defined %}
    {% set size = 0 %}
  {% endif %}
  <select name="{{ name }}"{% if id is defined %} id="{{ id }}"{% endif %}{% if size > 0  %} size="{{ size }}"{% endif %}{% if action is defined %}
    {{ action}}{% endif %}>
    {% for key, value in options %}
      <option value="{{ key }}"{% if selected == key %} selected="selected"{% endif %}>
        {{ value|e }}
      </option>
    {% endfor %}
  </select>
{% endmacro %}

{% macro selectwitharray(name, options, id, selected, action, size) %}
  {% if size is not defined %}
    {% set size = 0 %}
  {% endif %}
  <select name="{{ name }}"{% if id is defined %} id="{{ id }}"{% endif %}{% if size > 0  %} multiple="multiple" size="{{ size }}"{% endif %}{% if action is defined %}
    {{ action}}{% endif %}>
    {% for key, value in options %}
      {% set selectedflag = false %}
      {% for num, license in selected %}
        {% if license == value %}
          {% set selectedflag = true %}
        {% endif %}
      {% endfor %}
      <option value="{{ key }}" {% if selectedflag %}selected="selected"{% endif %}>
      {{ value|e }}
      </option>
    {% endfor %}
  </select>
{% endmacro %}

{% macro bootstrapalert(id, type) %}
  <div class="alert {% if type is defined %}alert-{{ type }}{% else %}alert-primary{% endif %} alert-dismissible fade show w-100" role="alert" id="{{ id }}" style="display:none">
    <span></span>
    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
      <span aria-hidden="true">&times;</span>
    </button>
  </div>
{% endmacro %}
